﻿package com.firewolf.junit;

import java.lang.reflect.InvocationTargetException;

import junit.framework.TestCase;
import junit.textui.TestRunner;
/**
 * 单元测试
 * @author Administrator
 *
 */
public class StringUtilTest extends TestCase{
	
	private StringUtil myUtil = null;
	
	@Override
	protected void setUp() throws Exception {
		myUtil = new StringUtil();
	}
	
	
	public void testgetUpAndLowStr(){ //测试共有方法
		assertEquals("LIUXING liuxing", StringUtil.getUpAndLowStr("Liuxing"));;
	}
	
	public void testgetUpperStr(){ //测试私有方法，
		try {
			String actualStr = (String) CallMethodUtil.invokeMethod(myUtil, "getUpperStr", "Liuxing");
			assertEquals("LIUXING", actualStr);
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
	}
	
	
	public void testgetLowerStr(){ //测私有方法
		try {
			String actualStr = (String) CallMethodUtil.invokeMethod(myUtil, "getLowerStr", "Liuxing");
			assertEquals("liuxing", actualStr);
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		
	}

	public void testaddString(){
		try {
			String actualStr = (String) CallMethodUtil.invokeMethod(myUtil, "addString",  new Object[]{"Liuxing",new Integer(2)});
			System.out.println(actualStr);
			assertEquals("Liuxing#2", actualStr);
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args){ //可有可无
        TestRunner.run(StringUtilTest.class);
    }
}
